package com.ny.mapper;

import com.ny.entity.User;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface UserMapper {

    @Delete("DELETE FROM user WHERE user_id = #{userId}")
    int deleteUser(@Param("userId") Integer userId);

    @Insert("INSERT INTO user(username, password, nickname, phone, email, is_active, created_time) " +
            "VALUES(#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{is_active}, NOW())")
    int addUser(User user);

    @Select("SELECT * FROM user WHERE email = #{email}")
    User findUserByEmail(String email);

    @Update("UPDATE user SET password = #{password} WHERE email = #{email}")
    int updatePassword(@Param("password") String password, @Param("email") String email);

    @Select("SELECT * FROM user ORDER BY created_time DESC")
    List<User> getAllUsers();

    @Select("SELECT * FROM user WHERE user_id = #{userId}")
    User getUserById(@Param("userId") Integer userId);
    // 根据用户名和加密后的密码查询用户
    @Select("select * from user where username= #{username} and password =#{password}")
    public User findUser(@Param("username") String username, @Param("password") String password);
}